home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / handson / Java / JBAdventure / AboutDialog.java next >
Encoding:
Java Source  |  1998-01-22  |  3.2 KB  |  125 lines

  1. /*
  2.     A basic extension of the java.awt.Dialog class
  3.  */
  4.  
  5. import java.awt.*;
  6.  
  7. public class AboutDialog extends Dialog {
  8.  
  9.     public AboutDialog(Frame parent, boolean modal)
  10.     {
  11.         super(parent, modal);
  12.  
  13.         // This code is automatically generated by Visual Cafe when you add
  14.         // components to the visual environment. It instantiates and initializes
  15.         // the components. To modify the code, only use code syntax that matches
  16.         // what Visual Cafe can generate, or Visual Cafe may be unable to back
  17.         // parse your Java file into its visual environment.
  18.  
  19.         //{{INIT_CONTROLS
  20.         setLayout(null);
  21.         setVisible(false);
  22.         setSize(insets().left + insets().right + 249,insets().top + insets().bottom + 150);
  23.         label1 = new java.awt.Label("Java  Adventure Game v 1.1");
  24.         label1.setBounds(insets().left + 40,insets().top + 35,166,21);
  25.         add(label1);
  26.         okButton = new java.awt.Button();
  27.         okButton.setLabel("OK");
  28.         okButton.setBounds(insets().left + 95,insets().top + 85,66,27);
  29.         add(okButton);
  30.         setTitle("About");
  31.         //}}
  32.  
  33.         //{{REGISTER_LISTENERS
  34.         SymWindow aSymWindow = new SymWindow();
  35.         this.addWindowListener(aSymWindow);
  36.         SymAction lSymAction = new SymAction();
  37.         okButton.addActionListener(lSymAction);
  38.         //}}
  39.  
  40.     }
  41.  
  42.     public AboutDialog(Frame parent, String title, boolean modal) 
  43.     {
  44.         this(parent, modal);
  45.         setTitle(title);
  46.     }
  47.  
  48.     public void addNotify()
  49.     {
  50.         // Record the size of the window prior to calling parents addNotify.
  51.         Dimension d = getSize();
  52.         
  53.         super.addNotify();
  54.  
  55.         // Only do this once.
  56.         if (fComponentsAdjusted)
  57.             return;
  58.  
  59.         // Adjust components according to the insets
  60.         setSize(insets().left + insets().right + getSize().width, insets().top + insets().bottom + getSize().height);
  61.         Component components[] = getComponents();
  62.         for (int i = 0; i < components.length; i++)
  63.         {
  64.             Point p = components[i].getLocation();
  65.             p.translate(insets().left, insets().top);
  66.             components[i].setLocation(p);
  67.         }
  68.         
  69.         // Used for addNotify check.
  70.         fComponentsAdjusted = true;
  71.     }
  72.  
  73.     public synchronized void show()
  74.     {
  75.         Rectangle bounds = getParent().bounds();
  76.         Rectangle abounds = bounds();
  77.  
  78.         move(bounds.x + (bounds.width - abounds.width)/ 2,
  79.              bounds.y + (bounds.height - abounds.height)/2);
  80.  
  81.         super.show();
  82.     }
  83.  
  84.     //{{DECLARE_CONTROLS
  85.     java.awt.Label label1;
  86.     java.awt.Button okButton;
  87.     //}}
  88.  
  89.     // Used for addNotify redundency check.
  90.     boolean fComponentsAdjusted = false;
  91.  
  92.     class SymWindow extends java.awt.event.WindowAdapter
  93.     {
  94.         public void windowClosing(java.awt.event.WindowEvent event)
  95.         {
  96.             Object object = event.getSource();
  97.             if (object == AboutDialog.this)
  98.                 AboutDialog_WindowClosing(event);
  99.         }
  100.     }
  101.  
  102.     void AboutDialog_WindowClosing(java.awt.event.WindowEvent event)
  103.     {
  104.                 dispose();
  105.     }
  106.  
  107.     class SymAction implements java.awt.event.ActionListener
  108.     {
  109.         public void actionPerformed(java.awt.event.ActionEvent event)
  110.         {
  111.             Object object = event.getSource();
  112.             if (object == okButton)
  113.                 okButton_Clicked(event);
  114.         }
  115.     }
  116.  
  117.     void okButton_Clicked(java.awt.event.ActionEvent event)
  118.     {
  119.         //{{CONNECTION
  120.         // Clicked from okButton Hide the Dialog
  121.                 dispose();
  122.         //}}
  123.     }
  124. }
  125.